--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit f052a447c7580a91d34b75739a43d9819a3e5d3f
Parents : 39ecb53
Author : Ivan <ivan@quad4.io>
Signature : Signature validation error
Date : 2026-05-07T20:31:16-05:00
fix(tests): update ConversationViewer tests with promise flushing and improve error handling in MessageSendingFailures
Changes
2 files changed, 29 insertions(+), 19 deletions(-)
Diff
diff --git a/tests/frontend/ConversationViewer.test.js b/tests/frontend/ConversationViewer.test.js
index e2d82a37..aa9ede1c 100644
--- a/tests/frontend/ConversationViewer.test.js
+++ b/tests/frontend/ConversationViewer.test.js
@@ -1,4 +1,4 @@
-import { mount } from "@vue/test-utils";
+import { mount, flushPromises } from "@vue/test-utils";
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import ConversationViewer from "@/components/messages/ConversationViewer.vue";
import WebSocketConnection from "@/js/WebSocketConnection";
@@ -544,6 +544,12 @@ describe("ConversationViewer.vue", () => {
selectedPeer: { destination_hash: peer, display_name: "Peer" },
myLxmfAddressHash: "c".repeat(32),
});
+ let guard = 0;
+ while (wrapper.vm.initialLoadActive && guard < 200) {
+ await flushPromises();
+ await wrapper.vm.$nextTick();
+ guard += 1;
+ }
const getCallsBefore = axiosMock.get.mock.calls.length;
await wrapper.vm.showRawMessage({
lxmf_message: {
diff --git a/tests/frontend/MessageSendingFailures.test.js b/tests/frontend/MessageSendingFailures.test.js
index 2efb3e1b..b5d66ad7 100644
--- a/tests/frontend/MessageSendingFailures.test.js
+++ b/tests/frontend/MessageSendingFailures.test.js
@@ -5,13 +5,6 @@ import WebSocketConnection from "@/js/WebSocketConnection";
import GlobalState from "@/js/GlobalState";
import DialogUtils from "@/js/DialogUtils";
-vi.mock("@/js/DialogUtils", () => ({
- default: {
- confirm: vi.fn(() => Promise.resolve(true)),
- alert: vi.fn(() => Promise.resolve()),
- },
-}));
-
describe("MessageSendingFailures.test.js", () => {
let axiosMock;
@@ -36,12 +29,16 @@ describe("MessageSendingFailures.test.js", () => {
// Mock URL.createObjectURL
window.URL.createObjectURL = vi.fn(() => "mock-url");
vi.spyOn(window, "open").mockImplementation(() => null);
+
+ vi.spyOn(DialogUtils, "confirm").mockResolvedValue(true);
+ vi.spyOn(DialogUtils, "alert").mockImplementation(() => {});
});
afterEach(() => {
delete window.api;
vi.unstubAllGlobals();
WebSocketConnection.destroy();
+ vi.restoreAllMocks();
});
const mountConversationViewer = (props = {}) => {
@@ -72,24 +69,31 @@ describe("MessageSendingFailures.test.js", () => {
};
it("handles API 503 failure when sending message", async () => {
+ axiosMock.post.mockImplementation((url) => {
+ if (typeof url === "string" && url.includes("/lxmf-messages/send")) {
+ return Promise.reject({
+ response: {
+ status: 503,
+ data: { message: "Sending failed" },
+ },
+ });
+ }
+ return Promise.resolve({ data: {} });
+ });
+
const wrapper = mountConversationViewer();
wrapper.vm.newMessageText = "Hello failure";
- axiosMock.post.mockRejectedValueOnce({
- response: {
- status: 503,
- data: { message: "Sending failed" },
- },
- });
-
await wrapper.vm.sendMessage();
+ await vi.waitFor(
+ () => {
+ expect(DialogUtils.alert).toHaveBeenCalledWith("Sending failed");
+ },
+ { timeout: 5000 }
+ );
- // Optimistic placeholder should be gone
const pendingItems = wrapper.vm.chatItems.filter((item) => item.lxmf_message.hash.startsWith("pending-"));
expect(pendingItems).toHaveLength(0);
-
- // Alert should be shown
- expect(DialogUtils.alert).toHaveBeenCalledWith("Sending failed");
});
it("sends plain text when crypto.randomUUID is unavailable (non-secure context)", async () => {
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────